<?php
defined('BASEPATH') OR exit('No direct script access allowed');
?>
<!--返回错误信息-->
<?php echo validation_errors(); ?>
<!DOCTYPE html>
<html lang="en">

<head>
    <?php
    $title = [
        'title' => '招投标项目审核',
    ];
    $this->load->view('/admin/common/header', $title);
    ?>
</head>

<body data-type="widgets">
<script src="/assets/js/theme.js"></script>
<div class="am-g tpl-g">

    <!--    头部   侧边菜单-->
    <?php $this->load->view('/admin/common/bodyLeft'); ?>
    <script type="text/javascript">
    	$(".js-sidebar-nav>li:nth-child(12)>ul").show(80);
    	$(".js-sidebar-nav>li:nth-child(12)>a>span").addClass("sidebar-nav-sub-ico-rotate");
    	$(".js-sidebar-nav>li:nth-child(12)>ul>li:nth-child(3)>a").addClass("active");
    </script>
    <!-- 内容区域 -->
    <div class="tpl-content-wrapper">
        <div class="row-content am-cf">
            <div class="row">
                <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
                    <form action="/admin/procurement/remove" id="form_admin" method="post">
                        <div class="widget am-cf">
                            <div class="widget-head am-cf">
                                <div class="widget-title  am-cf">
                                    <ol class="am-breadcrumb am-breadcrumb-slash">
                                        <li><a href="/admin/bidding/index?page=1">招投标管理</a></li>
                                        <li class="am-active">招标审核</li>
                                    </ol>
                                </div>
                            </div>
                            <div class="widget-body  am-fr">
                                <div class="am-u-sm-12 am-u-md-6 am-u-lg-6 am-form-group">
                                    <div class="am-btn-toolbar">
                                        <div class="am-alert am-alert-danger" id="data-alert" style="display: none;margin: 4px 0 10px 10px;font-size: 1.6rem;">
                                            <p>开始日期应小于结束日期</p>
                                        </div>
                                        <div class="am-g">
                                            <div class="am-u-sm-6">
                                                <button type="button" class="am-btn am-btn-default am-margin-right" id="my-start">开始日期</button><span id="my-startDate"></span>
                                            </div>
                                            <div class="am-u-sm-6">
                                                <button type="button" class="am-btn am-btn-default am-margin-right" id="my-end">结束日期</button><span id="my-endDate"></span>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="am-u-sm-12 am-u-md-6 am-u-lg-6">
                                    <div class="am-form-group">
                                    
                                    <div class="am-u-sm-12 am-u-md-6 am-u-lg-6">
                                        <div class="tpl-table-list-select">
                                            <select data-am-selected="{btnSize: 'sm',btnWidth: '100%'}" id="getStatus">
                                                <option value="null">请选择状态</option>
                                                <option value="0" >待评审</option>
                                                <option value="1" >评审中</option>
                                                <option value="2" >评审完成</option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="am-u-sm-12 am-u-md-6 am-u-lg-6">
                                        <div class="am-input-group am-input-group-sm tpl-form-border-form cl-p">
        <!--                                    <form action="/admin/user/search" method="get">-->
                                            <input type="text" class="am-form-field" name="search" id="searchValue" placeholder="请输入项目名称">
                                            <span class="am-input-group-btn">
                                                <a href="javascript:void(0);" id="search" class="am-btn  am-btn-default am-btn-success tpl-table-list-field am-icon-search">搜索</a>
                                            </span>
        <!--                                    </form>-->
                                        </div>
                                    </div>
                                    </div>
                                    
                                </div>
                                <div class="am-u-sm-12">
                                    <table width="100%" class="am-table am-table-compact am-table-striped tpl-table-black "
                                           id="example-r">
                                        <thead>
                                        <tr>
                                            <th>招投标项目编号</th>
                                            <th>需求单编号</th>
                                            <th>项目名称</th>
                                            <th>发布时间</th>
                                            <th>报名有效期</th>
                                            <th>地区</th>
                                            <th>联系人</th>
                                            <th>状态</th>
                                            <th>操作</th>
                                        </tr>
                                        </thead>
                                        <tbody class="choose-box">
                                        <?php
                                        if($list){
                                            foreach ($list as $v) {
                                                echo '
                                                <tr>
                                                 <td><a href="/admin/bidding/editView?id='.$v['biddingId'].'">'.$v['code'].'</a></td>';

                                                if(isset($v['needCode']) && isset($v['needId'])){
                                                    echo '<td><a href="/admin/procurement/editView?id='.$v['needId'].'">'.$v['needCode'].'</a></td>';
                                                }else{
                                                    echo '<td></td>';
                                                }

                                                 echo '<td>'.$v['name'].'</td>
                                                 <td>'.date('Y-m-d',$v['createTime']).'</td>
                                                 <td>'.$v['validTime'].'</td>
                                                 <td>'.$v['address'].'</td>
                                                 <td>'.$v['contactMan'].'</td>';

                                                switch ($v['status']){
                                                    case 0;
                                                        echo '<td>待评审</td>
                                                            <td>
                                                            <div class="tpl-table-black-operation">
                                                             <a href="javascript:void(0);" class="js-choose" data-id='.$v['id'].'>
                                                                    <i class="am-icon-check"></i> 选择评委
                                                                </a>
                                                            </div>
                                                            </tr>';
                                                        break;
                                                    case 1;
                                                        echo '<td>评审中</td><td>
                                                    <div class="tpl-table-black-operation">
                                                    
                                                    </div>
                                                    </tr>';
                                                        break;
                                                    case 2;
                                                            echo '<td>评审完成</td><td>
                                                    <div class="tpl-table-black-operation">
                                                   
                                                </div>
                                                </tr>';

                                                        break;
                                                }
//                                                <td>'.date('Y-m-d H:i:s',$v['createTime']).'</td>
                                            }
                                        }else{
                                            echo '';
                                        }
                                        ?>
                                        </tbody>
                                    </table>
                                </div>
                                <div class="am-u-lg-12">
                                    <div class="am-u-sm-centered">
                                        <ul class="am-pagination am-pagination-centered" id="paging">

                                        </ul>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </form>

                </div>
            </div>
        </div>
    </div>
</div>
</div>

<!-- 选择评委弹出框 -->
<div class="am-modal am-modal-no-btn" tabindex="-1" id="pop-up-box" style="">
  <div class="am-modal-dialog" style="width: 650px;">
    <div class="am-modal-hd">选择评委
      <a href="javascript: void(0)" class="am-close am-close-spin" data-am-modal-close>&times;</a>
    </div>
    
    <div class="am-modal-bd r_pt am-cf">
        <div class="am-u-sm-12">
          <table class="am-table am-table-bordered am-table-radius am-table-striped am-table-hover">
            <thead>
              <tr>
                <th><input type="checkbox" class="check-all" name=""></th>
                <th>序号</th>
                <th>姓名</th>
                <th>角色</th>
              </tr>
            </thead>
            <tbody class="tr-box"></tbody>
          </table>
        </div>

        <div class="pagination-box">
          <ul class="am-pagination r_position-static" id="pagination">

          </ul>
        </div>
    </div>
        <div class="am-form-group search-box">
          <button type="button" class="am-btn am-btn-primary" id="btn-sure" data-am-modal-close>确认</button>
        </div>
</div>
<script>
    function search123() {
        var v = document.getElementById('search').value;
        console.log(v);

//        console.log(document.getElementById('searchData').value);
        window.location.href='?page=1'+'&search='+v

    }
</script>

<script src="/assets/js/amazeui.min.js"></script>
<script src="/assets/js/amazeui.datatables.min.js"></script>
<script src="/assets/js/dataTables.responsive.min.js"></script>
<script src="/assets/js/app.js"></script>
<script src="/assets/js/page.js"></script>
<script>
    //todo 第一次选中可以,第二次不行
    /* 全选 */
    $('.checkall').click(function(){
        var _self = this;
        $('.checkitem').each(function(){
            if (!this.disabled)
            {
                $(this).attr('checked', _self.checked);
            }
        });
        $('.checkall').attr('checked', this.checked);
    });
    
    // 选择评委 
    $(function() {
        var arr = [];
        var arrSelect = [];
        var id;
        
        // 选择评委 按钮
        $(document).on("click",".js-choose",function() {
            id = $(this).attr("data-id");
            $("#pop-up-box").modal();
                postDataByPage(1);
        }); 
        
        function postDataByPage(p) {
            $.ajax({
                type:"post",
                url:"/admin/bidding/choose",
                data: {
                    type:"招标评审员",
                    page: p
                },
                async:true,
                dataType: "json",
                success: function(data) { 
                    console.log(data);
                    arr = [];
                    for (var key in data) {
                        if (key == "total_num" || key == "pageNum") {
                            break;
                        } else {
                            arr.push(data[key]);
                        }
                    }
                    // 数据列表         
                        changeDomOfPopoverList();
                        
                    // 分页列表
                    totalPage = Math.ceil(data["total_num"] / data["pageNum"]); 
                        changeDomOfPage(p);
                }
            });         
        }
        
          function changeDomOfPopoverList() {
            var html = '';
            for (var i = 0; i < arr.length; i++) {
                var obj = arr[i];
                    var isCheck = "";
                for (var j = 0; j < arrSelect.length; j++) {
                    if (arrSelect[j] == obj.nickname) {
                        isCheck = "checked";
                        break;
                    }
                }                   
                html += '<tr>';
                    html += '   <td><input type="checkbox" class="check-one" data-id=' + obj.id + ' ' + isCheck + '></td>';
                    html += '   <td>' + obj.id + '</td>';
                    html += '   <td>' + obj.nickname + '</td>';
                    html += '   <td>招标评审员</td>';
                    html += '</tr>';                
            }
            $(".tr-box").html(html);        
            
                isCheckedOfUpper();
          }   
          
          // 判断全选框的状态
          function isCheckedOfUpper() {
            isCheck = $(".check-one:checked").size() == arr.length;
            $(".check-all").prop("checked", isCheck);       
          }
          
          function changeDomOfPage(p) {
                var html = '';
                html += '<li><a href="javascript:void(0)" class="prev-page">&laquo;</a></li>';
                for (var i = 1; i < totalPage + 1; i++) {
                    strClass = i == p ? "am-active" : "";                   
                    html += '<li class="' + strClass + '"><a href="javascript:void(0)">' + i + '</a></li>';
                }                   
          html += '<li><a href="javascript:void(0)" class="next-page">&raquo;</a></li>';
          $("#pagination").html(html);      
          } 
                
        //全选反选
        $(document).on("click", ".check-all", function() {
            var isCheck = this.checked;
            $(".check-one").each(function() {
                if (isCheck && !this.checked) {
                    // 全选, 单个未选中时
                    $(this).prop("checked", isCheck);
                    var i = $(this).parents("tr").index();
                    arrSelect.push(arr[i].nickname);                                
                } else if (!isCheck && this.checked) {
                    // 全不选, 单个选中时
                    $(this).prop("checked", isCheck);
                    var i = $(this).parents("tr").index();
                    arrSelect.splice(arrSelect.indexOf(arr[i].nickname), 1);            
                }           
            });         
        });
        
        $(document).on("click", ".check-one", function() {
            isCheckedOfUpper();
            
            var i = $(this).parents("tr").index();
                if (this.checked) {             
                    arrSelect.push(arr[i].nickname);
                } else {
                    arrSelect.splice(arrSelect.indexOf(arr[i].nickname), 1);
                }
       });  
       
      //  弹框中, 上下页按钮
      $(document).on("click", ".prev-page", function() {
        if ($(this).parent().next().prop("class") == "am-active") {
            return;
        }
        var pageActive = $("#pagination>.am-active>a").text();
        pageActive--;
        postDataByPage(pageActive);
      });     
      
      $(document).on("click", ".next-page", function() {
        if ($(this).parent().prev().hasClass("am-active")) {
            return;
        }       
        var pageActive = $("#pagination>.am-active>a").text();
        pageActive++;
        postDataByPage(pageActive);
      });   
      // 选择供应商 弹框中, 分页按钮  
      $(document).on("click", "#pagination>li>a", function() {
        if ($(this).hasClass("prev-page") || $(this).hasClass("next-page") || $(this).parent().hasClass("am-active")) {
            return;
        }
        postDataByPage($(this).text());
      });
        
        // 确认 按钮
        $("#btn-sure").click(function() {
            if (arrSelect.length == 0) {
                console.log(0);
                return;
            } 
            $.ajax({
                type:"post",
                url:"/admin/bidding/confirmPeople",
                data: {
                    checkPeople: JSON.stringify(arrSelect),
                    id: id
                    },
                    dataType: "json",
                async:true,
                success: function(data) {
                    // console.log(data);
                    window.location.reload();
                }
            });
        });


        //筛选
        var startTime,
        endTime,
        status,
        searchValue,
        page;

        $("#getStatus").on( "change" , function() {
            startTime = $("#my-startDate").text();
            endTime = $("#my-endDate").text();
            status = $("#getStatus").val();
            searchValue = $("#searchValue").val();
            page = 1;

            chooseProject(startTime,endTime,status,searchValue,page)

        });
        $("#search").on( "click" , function() {
            startTime = $("#my-startDate").text();
            endTime = $("#my-endDate").text();
            status = $("#getStatus").val();
            searchValue = $("#searchValue").val();
            page = 1;

            chooseProject(startTime,endTime,status,searchValue,page);
        });

        //筛选日期
        var startDate = new Date(2014, 11, 20);
        var endDate = new Date(2100, 11, 25);
        var $alert = $('#data-alert');
        $('#my-start').datepicker().on('changeDate.datepicker.amui', function(event) {
            
            if (event.date.valueOf() > endDate.valueOf()) {
              $alert.find('p').text('开始日期应小于结束日期！').end().show();
              return false;
              
            } else {
              $alert.hide();
              startDate = new Date(event.date);
              $('#my-startDate').text($('#my-start').data('date'));
            }
            $(this).datepicker('close');

            startTime = $("#my-startDate").text();
            endTime = $("#my-endDate").text();
            status = $("#getStatus").val();
            searchValue = $("#searchValue").val();
            page = 1;

            chooseProject(startTime,endTime,status,searchValue,page);
            
        });
        $('#my-end').datepicker().on('changeDate.datepicker.amui', function(event) {
            
            if (event.date.valueOf() < startDate.valueOf()) {
              $alert.find('p').text('结束日期应大于开始日期！').end().show();
              return false;
            } else {
              $alert.hide();
              endDate = new Date(event.date);
              $('#my-endDate').text($('#my-end').data('date'));
            }
            $(this).datepicker('close');

            startTime = $("#my-startDate").text();
            endTime = $("#my-endDate").text();
            status = $("#getStatus").val();
            searchValue = $("#searchValue").val();
            page = 1;

            chooseProject(startTime,endTime,status,searchValue,page);
           
        });

        function chooseProject(startTime,endTime,status,searchValue,page){
            $.ajax({
                type: "GET",
                url : "/api/bidding/checkListSearch",
                data: {
                    startTime:startTime,
                    endTime: endTime,
                    status: status,
                    search: searchValue,
                    page: page
                },
                dataType: "json",
                beforeSend:function(){
                    $(".my-dark").css("display","block");
                },
                success: function(msg){
                    var data = msg['0'];
                    var list,
                        needCode,
                        validTime,
                        operation,
                        listStatus;
                    console.log(data);
                    if(!data[0]){
                        list += '<tr class="gradeX"><td colspan="9">暂无数据</td></tr>';
                    }else{
                        for(var i = 0 ; i < data.length;i++ ){
                            if(data[i].code && data[i].needId){
                                needCode = '<a href="/admin/procurement/editView?id='+ data[i].needId +'">'+ data[i].needCode +'</a>';
                            }else{
                                needCode = '';
                            }

                            listStatus = data[i].status == 0 ? '待评审' :
                                        data[i].status == 1 ? '评审中': '评审完成';

                            operation = data[i].status == 0 ? '<div class="tpl-table-black-operation"><a href="javascript:void(0);" class="js-choose" data-id='+ data[i].id +'><i class="am-icon-check"></i> 选择评委</a></div>' : '';
                            
                            list += '<tr>'
                                    +'<td>'
                                        + '<a href="/admin/bidding/editView?id='+ data[i].biddingId +'">'+ data[i].code +'</a>'
                                    + '</td>'
                                    + '<td>'+ needCode +'</td>'
                                    + '<td>'+ data[i].name +'</td>'
                                    + '<td>'+ data[i].createTime +'</td>'
                                    + '<td>'+ data[i].validTime +'</td>'
                                    + '<td>'+ data[i].address +'</td>'
                                    + '<td>'+ data[i].contactMan +'</td>'
                                    + '<td>'+ listStatus +'</td>'
                                    + '<td>'+ operation +'</td>'
                                 + '</tr>';
                        }

                    }
                    $(".choose-box").html(list);

                    //分页
                    //设置分页信息  
                    var pageOptions = {  
                        AllowPaging: true,  
                        PageIndex: msg.this_page,      //设置当前页码  
                        PageSize: msg.pageNum,       //设置分页大小  
                        RecordCount: msg.total_num,  //设置数据总数  
                        // TotalPage: ,      //设置总页数
                        showPageCount: 4,  
                        onPageClick: function(pageIndex) {  
                            chooseProject(startTime,endTime,status,searchValue,pageIndex)
                        }  
                    }  
                    //初始化分页栏  
                    $('#paging').pageBar(pageOptions); 

                },
                complete:function(){
                    $(".my-dark").css("display","none");
                },
                error: function (data) {  
                   //  alert(XMLHttpRequest.status);
                   //  alert(XMLHttpRequest.readyState);
                   //  alert(textStatus);
                }
            });
        }



            
    });
</script>
<script>
    $(document).ready(function() {  
        //设置分页信息  
        var pageOptions = {  
            AllowPaging: true,  
            PageIndex: <?php echo $_GET['page'] ?>,      //设置当前页码  
            PageSize: <?php echo $pageNum ?>,       //设置分页大小  
            RecordCount: <?php echo $totalNum ?>,  //设置数据总数  
            // TotalPage: ,      //设置总页数
            showPageCount: 4,  
            onPageClick: function(pageIndex) {  
                var search = '<?php echo isset($_GET['search'])  ? $_GET['search'] : 0 ?>';
                var page = parseInt(pageIndex);
                if(search){
                    window.location.href = "?page="+ page + "&search=" + search; 
                }else {
                    window.location.href = "?page="+ page;
                }
            }  
        }  
        //初始化分页栏
        $('#paging').pageBar(pageOptions);      
    })  
</script>
</body>

</html>